$(function() {
	var voteid = $(".voteid").val();
	var voteLimit = $('#vote_limit').val();
	//投票
	$(document).on('click',".canvote",function(){
		var em = $(this);
		var optionid = $(this).siblings(".optionid").val();		
		$.ajax({
			'url': "/activity/vote/doVote/vote_id/"+voteid,
			'data': {'option_id':optionid,'vote_id':voteid},
			'dataType':'json',
			'type': 'POST',
			'async': false,
			success: function(data) {
				if (data.status == 'S') { //投票成功
					em.removeClass("canvote");
					em.children().addClass('isVoted');
					var num = em.children().data('num');
					num = num + 1;
					em.children().html('已投票<br/>（'+num+'票）');
					$.alert('success',data.message);
					return false;
				}else{
					if((data.data == 'notSubscribe') && (voteLimit == 2)){
						//$('#qrcode').show();
						window.location.hash = "#qrcode";
					}
					$.alert('error',data.message);					
					return false;
				}
			}
		});
	});
	
	//获取选项详情
   $(document).off('click', '.list-container .show-box').on('click','.list-container .show-box', function () {
      var id = $(this).data('id');
      $.ajax({
			method : 'post',
			url : "/activity/vote/getOptionInfo/vote_id/"+voteid,
			data : {'id':id},
			dataType : 'json',
			success : function(data){
				if(data.status == 'S'){
					var html = '<img height="250px;" src="' + data.url + '"><p><span>'+ data.content +'</span></p><button class="md-close"><span class="iconfont icon-close"></span></button>';
			        $('.inner-content').html(html);
				    $('.md-modal').addClass('md-show');
				}else{
					$.alert('error', data.message);					
					return false;
				}	
			},
			error:function(data){
				$.alert('error', data.message);					
				return false;
			}
		});
   });
   
	$(document).on('click','.inner-content img',function(){
		$('.md-modal').removeClass('md-show');
	});

	$(document).on('click','body',function(){
		$('.md-modal').removeClass('md-show');
	});
});